var city = '沧州'

function loadXMLDoc() {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp = new XMLHttpRequest();
    }
    else {
        // IE6, IE5 浏览器执行代码
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var json = JSON.parse(xmlhttp.responseText);
            document.querySelector("#city").innerHTML = json.basic.city;
            var li =document.querySelectorAll(".ul-2 li")
            console.log(li)
            for(let i = 0; i< li.length;i++){
                //天
                li[i].children[1].innerHTML = json.daily_forecast[i].date.slice(5);
                //天气
                li[i].children[2].innerHTML = json.daily_forecast[i].cond.txt_d;
                //风向
                li[i].children[3].innerHTML =json.daily_forecast[i].wind.dir;
                //温度
                li[i].children[4].innerHTML = json.daily_forecast[i].tmp.max+"/"+json.daily_forecast[i].tmp.min+"℃"
                //几级风
                li[i].children[5].innerHTML = json.daily_forecast[i].wind.sc;
            }
            var lil=document.querySelectorAll(".ul-3 li")
            console.log(lil)
            for(let t=0; t<lil.length;t++){
                //时间段
                lil[t].children[0].innerHTML = json.hourly_forecast[t].date.slice(10);
                //温度
                lil[t].children[1].innerHTML = json.daily_forecast[t].tmp.min+"℃";
                //风向
                lil[t].children[2].innerHTML =json.daily_forecast[t].wind.dir;
                 //几级风
                 lil[t].children[3].innerHTML = json.daily_forecast[t].wind.sc+"级";
                // 穿衣指数
                 document.querySelector("#li1").innerHTML =json.suggestion.drsg.txt;

                 document.querySelector("#li2").innerHTML =json.suggestion.drsg.txt;

                 document.querySelector("#li3").innerHTML =json.suggestion.drsg.txt;

                 document.querySelector("#li4").innerHTML =json.suggestion.drsg.txt;

                 document.querySelector("#li5").innerHTML =json.suggestion.drsg.txt;

                 document.querySelector("#li6").innerHTML =json.suggestion.drsg.txt;
            }


        }
    }
    xmlhttp.open("GET", "https://bird.ioliu.cn/weather?city=" + city, true);
    xmlhttp.send();
}
loadXMLDoc();

document.querySelector("#inp").addEventListener('change',function(){
    console.log(this.value);
    //执行获取天气的函数
    city = this.value;
    loadXMLDoc()
})